﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.LIB;

namespace YJKCopyModel.Forms
{
	public partial class QuickModelProgressBar : System.Windows.Forms.Form
	{
		public QuickModelProgressBar(string inputTitle = null)
		{
			this.InitializeComponent();
			//base.Icon = Resource.YArchitechIcon;
			Application.EnableVisualStyles();
			this.MainprogressBar.Value = 1;
			this.MainprogressBar.Maximum = 10;
			bool flag = !string.IsNullOrWhiteSpace(inputTitle);
			if (flag)
			{
				this.Text = inputTitle;
			}
			this.useStartTime = DateTime.Now;
			this.TimerLabel.Text = "计时:0秒";
			base.ShowInTaskbar = false;
		}

		public bool StopTag
		{
			get
			{
				return this.m_stopTag;
			}
			private set
			{
				this.m_stopTag = value;
			}
		}

		public void SetSubMaxValue(int inputLength)
		{
			this.SubprogressBar.Value = 0;
			this.SubprogressBar.Maximum = inputLength;
			bool flag = this.tempSubCount != -1;
			if (flag)
			{
				bool flag2 = 5 >= this.MainprogressBar.Value;
				if (flag2)
				{
					this.MainprogressBar.Value = 5;
				}
				Application.DoEvents();
			}
			this.tempSubCount++;
		}

		public void RefreshProgressBarText(string inputSubLable = null)
		{
			bool flag = !string.IsNullOrWhiteSpace(inputSubLable) && !this.labelSub.Text.Equals(inputSubLable);
			if (flag)
			{
				this.labelSub.Text = inputSubLable;
			}
			TimeSpan timeSpan = DateTime.Now - this.useStartTime;
			this.TimerLabel.Text = string.Format("计时:{0}秒", (int)timeSpan.TotalSeconds);
			Application.DoEvents();
		}

		public void RefreshProgressBar(string inputSubLable = null)
		{
			bool flag = this.SubprogressBar.Value < this.SubprogressBar.Maximum;
			if (flag)
			{
				ProgressBar subprogressBar = this.SubprogressBar;
				int value = subprogressBar.Value;
				subprogressBar.Value = value + 1;
				bool flag2 = !string.IsNullOrWhiteSpace(inputSubLable) && !this.labelSub.Text.Equals(inputSubLable);
				if (flag2)
				{
					this.labelSub.Text = inputSubLable;
				}
				TimeSpan timeSpan = DateTime.Now - this.useStartTime;
				this.TimerLabel.Text = string.Format("计时:{0}秒", (int)timeSpan.TotalSeconds);
				double num = (double)this.SubprogressBar.Value / (double)this.SubprogressBar.Maximum;
				int num2 = 5;
				int num3 = (this.tempSubCount == 0) ? ((int)((double)num2 * num)) : (num2 + (int)((double)num2 * num));
				bool flag3 = num3 >= this.MainprogressBar.Value;
				if (flag3)
				{
					this.MainprogressBar.Value = num3;
				}
				bool flag4 = this.MainprogressBar.Value < this.MainprogressBar.Maximum;
				if (flag4)
				{
					Application.DoEvents();
				}
				else
				{
					this.m_stopTag = false;
					base.Dispose();
				}
			}
		}

		private void QuickModelProgressBar_FormClosing(object sender, FormClosingEventArgs e)
		{
			bool flag = MessageBox.Show("你确定终止吗", "终止", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes;
			if (flag)
			{
				this.m_stopTag = false;
				e.Cancel = true;
			}
			else
			{
				this.m_stopTag = true;
			}
		}

		private void CancleButton_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private const int useMainMaximum = 10;

		private DateTime useStartTime;

		private int tempSubCount = -1;

		private bool m_stopTag = false;
	}
}
